/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2015年1月4日         luwei
 */

package com.coocaa.launcher.sidebar.setting;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.coocaa.launcher.framework.sidebar.ItemContainer;
import com.coocaa.launcher.framework.sidebar.item.ItemFactory.ITEM;
import com.coocaa.x.uipackage.BaseView;
import com.coocaa.x.uipackage.SkinManager;
import com.tianci.appstore.R;
import com.tianci.appstore.utils.SkyConstants;

public abstract class SettingLayout extends BaseView {
    protected Context mContext = null;
    protected ItemContainer mItemContainer = null;
    protected String mType = ITEM.SETTING.toString();

    public SettingLayout(Context context, String type) {
        super(context);
        this.mContext = context;
        this.mType = type;
        setFocusable(false);
        setFocusableInTouchMode(false);
        setClickable(false);
        addTitleView();
        addDivideLine();
        addContent();
        SkinManager.getInstance().setBackgroundResource(this, R.drawable.launcher_bg);
    }

    @SuppressLint("ResourceAsColor")
    public void addTitleView() {
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                SkyConstants.Div(396),
                LayoutParams.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL);
        mItemContainer = getTitleItemContainer();
        addView(mItemContainer.getLayout(), params);
        mItemContainer.getLayout().setBackgroundColor(android.R.color.transparent);
        if (mItemContainer.getItems().size() > 1) {
            mItemContainer.getItems().get(0).getView().requestFocus();
        }
    }

    public void addDivideLine() {
        ImageView imageView = new ImageView(mContext);
        SkinManager.getInstance().setBackgroundResource(imageView, R.drawable.launcher_setting_divide);
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                SkyConstants.Div(687), Gravity.CENTER_VERTICAL);
        params.leftMargin = SkyConstants.Div(396);
        addView(imageView, params);
    }

    public void addContent() {
        View view = getContentView();
        if (view.getLayoutParams() == null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
            addView(getContentView(), params);
        } else {
            addView(view);
        }
    }

    public abstract ItemContainer getTitleItemContainer();

    public abstract View getContentView();

    public void destory() {

    }
}
